using System;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

public class UIPropertyShow : AssemblerPropertyShow
{
    public TextMeshProUGUI scoreText;
    public TextMeshProUGUI heightText;
    public Slider heightProgress;
    public TextMeshProUGUI weightText;
    public Slider weightProgress;
    public TextMeshProUGUI incomeText;
    public Slider incomeProgress;
    public TextMeshProUGUI educationText;
    public Slider educationProgress;
    
    public override void Init(Player assmebler)
    {
        var fiveDimensions = assmebler.data;
        this.heightProgress.value = GetMaleHeightProgress(fiveDimensions.height);
        heightText.text = $"{DataString.GetHeightString(fiveDimensions.height)}";
        this.weightProgress.value = GetMaleWeightProgress(fiveDimensions.weight);
        weightText.text = $"{fiveDimensions.weight}kg";
        this.incomeProgress.value = fiveDimensions.income/maleMaxIncome;
        incomeText.text = $"Annual: ${fiveDimensions.income}";
        this.educationProgress.value = (float)fiveDimensions.eduation / maxEducation;
        educationText.text = $"{DataString.GetEducationString(fiveDimensions.eduation)}";

        scoreText.text = GetScore(fiveDimensions).ToString();
    }

    static float GetMaleHeightProgress(float height)
    {
        return (height - maleMinHeight) / (maleMaxHeight - maleMinHeight);
    }
    static float GetMaleWeightProgress(float weight)
    {
        return (weight - maleMinWeight) / (maleMaxWeight - maleMinWeight);
    }
    public static int GetScore(UserInfo fiveDimensions)
    {
        float score = (GetMaleHeightProgress(fiveDimensions.height)
                       + fiveDimensions.income / maleMaxIncome 
                       + GetMaleWeightProgress(fiveDimensions.weight)
                       + (float)fiveDimensions.eduation / maxEducation
                       //+ (float)fiveDimensions.birthYear)
            )
                      * 25;
        
        return (int) score;
    }
    static float GetFemaleHeightProgress(float height)
    {
        return (height - femaleMinHeight) / (femaleMaxHeight - femaleMinHeight);
    }
    static float GetFemaleWeightProgress(float weight)
    {
        return (weight - femaleMinWeight) / (femaleMaxWeight - femaleMinWeight);
        /*var center = (femaleMaxWeight + femaleMinWeight) / 2;
        return  100 - Mathf.Abs(weight - center) * (100 / (femaleMaxWeight - center));*/
    }
    public static int GetCandidateScore(FiveDimensions fiveDimensions)
    {
        float score = (GetFemaleHeightProgress(fiveDimensions.Height)
                       + fiveDimensions.Income / femaleMaxIncome 
                       + GetFemaleWeightProgress(fiveDimensions.Weight)
                       + (float)fiveDimensions.Education / maxEducation
                          //+ (float)fiveDimensions.birthYear)
                      )
                      * 25;
        
        return (int) score;
    }
    public const int maxEducation = 4;
    public const float maleMinHeight = 150;
    public const float maleMaxHeight = 185;
    public const float maleMinWeight = 40;
    public const float maleMaxWeight = 80;
    public const float maleMaxIncome = 200000;
    
    public const float femaleMinHeight = 140;
    public const float femaleMaxHeight = 175;
    public const float femaleMinWeight = 40;
    public const float femaleMaxWeight = 65;
    public const float femaleMaxIncome = 100000;
    
}